import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
export const columns: BasicColumn[] = [
  {
    title: '用户ID',
    dataIndex: 'id',
    width: 140,
  },
  {
    title: '用户账号',
    dataIndex: 'username',
    width: 100,
  },
  {
    title: '用户姓名',
    dataIndex: 'realname',
    width: 80,
  },
  {
    title: '实名认证',
    dataIndex: 'authenticationStatus',
    width: 80,
    customRender: ({ text }) => {
      return render.renderDict(text, 'authenticationStatus',true);
    },
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    width: 100,
  },
  // {
  //   title: '团队',
  //   width: 100,
  //   dataIndex: 'orgCodeTxt',
  // },
  {
    title: '团队抽佣奖励类型',
    dataIndex: 'teamCommissionType',
    width: 120,
    customRender: ({ text }) => {
      return render.renderDict(text, 'TeamCommissionType',true);
    },
  },
  {
    title: '抽佣比例',
    dataIndex: 'commissionRate',
    width: 80,
  },
  {
    title: '团队抽佣比例',
    dataIndex: 'teamCommissionRate',
    width: 80,
  },
  {
    title: '邀请码',
    dataIndex: 'genCode',
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'status_dictText',
    width: 80,
  },
  {
    title: '注册时间',
    dataIndex: 'createTime',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: 'ID',
    field: 'Id',
    component: 'Input',
    //colProps: { span: 6 },
  },
  {
    label: '账号',
    field: 'username',
    component: 'Input',
    //colProps: { span: 6 },
  },
  {
    label: '名字',
    field: 'realname',
    component: 'Input',
   //colProps: { span: 6 },
  },
  {
    label: '团队提成奖励类型',
    field: 'teamCommissionType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'TeamCommissionType',
      placeholder: '类型',
      stringToNumber: true,
    },
    //colProps: { span: 6 },
  },
  {
    label: '手机号码',
    field: 'phone',
    component: 'Input',
    //colProps: { span: 6 },
  },
  {
    label: '用户状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'user_status',
      placeholder: '请选择状态',
      stringToNumber: true,
    },
   //colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '用户账号',
    field: 'username',
    component: 'Input',
    required: true,
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
    dynamicRules: ({ model, schema }) => rules.duplicateCheckRule('sys_user', 'username', model, schema, true),
  },
  {
    label: '用户姓名',
    field: 'realname',
    // required: true,
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
  },
  // {
  //   label: '角色',
  //   field: 'selectedroles',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     mode: 'multiple',
  //     api: getAllRolesListNoByTenant,
  //     labelField: 'roleName',
  //     valueField: 'id',
  //     immediate: false,
  //   },
  // },
  // {
  //   label: '所属部门',
  //   field: 'selecteddeparts',
  //   component: 'JSelectDept',
  //   componentProps: ({ formActionType, formModel }) => {
  //     return {
  //       sync: false,
  //       checkStrictly: true,
  //       defaultExpandLevel: 2,
  //       onSelect: (options, values) => {
  //         const { updateSchema } = formActionType;
  //         //所属部门修改后更新负责部门下拉框数据
  //         updateSchema([
  //           {
  //             field: 'departIds',
  //             componentProps: { options },
  //           },
  //         ]);
  //         //update-begin---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
  //         if(!values){
  //           formModel.departIds = [];
  //           return;
  //         }
  //         //update-end---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
  //         //所属部门修改后更新负责部门数据
  //         formModel.departIds && (formModel.departIds = formModel.departIds.filter((item) => values.value.indexOf(item) > -1));
  //       },
  //     };
  //   },
  // },
  // {
  //   label: '租户',
  //   field: 'relTenantIds',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     mode: 'multiple',
  //     api: getAllTenantList,
  //     numberToString: true,
  //     labelField: 'name',
  //     valueField: 'id',
  //     immediate: false,
  //   },
  // },
  {
    label: '身份',
    field: 'userIdentity',
    component: 'RadioGroup',
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '普通用户', value: 1, key: '1' },
          { label: '团队长', value: 2, key: '2' },
        ],
        onChange: () => {
          formModel.userIdentity == 1 && (formModel.departIds = []);
        },
      };
    },
  },
  // {
  //   label: '负责部门',
  //   field: 'departIds',
  //   component: 'Select',
  //   componentProps: {
  //     mode: 'multiple',
  //   },
  //   ifShow: ({ values }) => values.userIdentity == 2,
  // },
  // {
  //   label: '头像',
  //   field: 'avatar',
  //   component: 'JImageUpload',
  //   componentProps: {
  //     fileMax: 1,
  //   },
  // },
  // {
  //   label: '生日',
  //   field: 'birthday',
  //   component: 'DatePicker',
  // },
  // {
  //   label: '性别',
  //   field: 'sex',
  //   component: 'JDictSelectTag',
  //   componentProps: {
  //     dictCode: 'sex',
  //     placeholder: '请选择性别',
  //     stringToNumber: true,
  //   },
  // },
  {
    label: '手机号码',
    field: 'phone',
    component: 'Input',
    required: true,
    dynamicRules: ({ model, schema }) => {
      return [
        { ...rules.duplicateCheckRule('sys_user', 'phone', model, schema, true)[0], trigger: 'blur' },
        { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式有误', trigger: 'blur' },
      ];
    },
  },
  {
    label: '团队奖励类型',
    field: 'teamCommissionType',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'TeamCommissionType',
      type: 'radio',
    },
  },
  {
    label: '抽佣比率',
    field: 'commissionRate',
    component: 'Input',
    rules: [{ pattern: /^0\.[1-7]$/, message: '请输入正确的抽佣比例，比例不得超过0.7' }],
  },
  {
    label: '团队长抽佣比率',
    field: 'teamCommissionRate',
    component: 'Input',
    rules: [{ pattern: /^(0\.05|0\.10?)$/, message: '请输入正确的团队长抽佣比例，比例仅限5% 或 10% ' }],
  },
];